package com.util;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DetermineParamType {

	public static void determine(PreparedStatement ps, int index, Object value) throws SQLException{
		if(null == value){
			ps.setString(index, null);
		}else
		if(value instanceof Date){
			ps.setObject(index,toString((Date)value, "yyyy-MM-dd HH:mm:ss"));
		}else{
			ps.setObject(index, value);
		}
	}
	public static String toString(Date d, String fmt) {
		if (null == d)
			return "";

		try {
			SimpleDateFormat sdf = new SimpleDateFormat(fmt);
			return sdf.format(d);
		} catch (Exception e) {

		}
		return d.toString();
	}
}
